package com.example.go_drink_water_plugin.component;

import com.example.go_drink_water_plugin.AppConfig;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

public class SettingsDialog extends DialogWrapper {

    private JCheckBox enableCheckbox;
    private JSpinner intervalSpinner;

    public SettingsDialog() {
        // 使用true来创建带true,false的对话框
        super(true);
        setTitle("设置您的喝水提醒");
        init();
    }

    @Nullable
    @Override
    protected JComponent createCenterPanel() {
        JPanel panel = new JPanel(new BorderLayout());

        enableCheckbox = new JCheckBox("是否开启提醒：", AppConfig.isReminderEnabled);
        intervalSpinner = new JSpinner(new SpinnerNumberModel(AppConfig.reminderInterval, 1, 60, 1));

        panel.add(enableCheckbox, BorderLayout.NORTH);
        panel.add(new JLabel("设置喝水间隔时间（分钟）："), BorderLayout.WEST);
        panel.add(intervalSpinner, BorderLayout.CENTER);

        return panel;
    }

    public boolean isReminderEnabled() {
        return enableCheckbox.isSelected();
    }

    public int getReminderInterval() {
        return (Integer) intervalSpinner.getValue();
    }
}
